proc do_access {nick chan otbn1 host} {
  # This proc MUST be kept as streamlined as possible

  global home botnick bcast

  if {![validchan $chan]} {
    putquick "NOTICE $nick :\0034ERROR: \002$chan\002 is not a registered channel."
    return 0
  } elseif {$otbn1 == ""} {
    putquick "NOTICE $nick :\0034ERROR: Please use: \002(/msg) $botnick access <#channel> <nick>\002"
    return 0
  } elseif {![onchan $otbn1 $chan]} {
    putquick "NOTICE $nick :\0034ERROR: \002$otbn1\002 isn't in $chan"
    return 0
  }

  if {[validuser $otbn1]} {
    set hand2 $otbn1
    set hand3 [nick2hand $hand2 $chan]
  } elseif {[validuser [nick2hand $otbn1 $chan]]} {
    set hand2 $otbn1
    set hand3 [nick2hand $hand2 $chan]
  } else {
    putquick "NOTICE $nick :\0034ERROR: \002$otbn1\002 is not a valid user."
    return 0
  }

  set access "N/A"

  # Default global access to null string for use later on  
  set gaccess "" 

  if {[matchattr $hand3 |v $chan]} {
    set access "Automatically Voiced"
  } elseif {[matchattr $hand3 |a $chan]} {
    set access "Automatic Operator"
  } elseif {[matchattr $hand3 |o $chan]} {
    set access "Channel Operator"
  } elseif {[matchattr $hand3 |m $chan]} {
    set access "Channel Co-Administrator"
  } elseif {[matchattr $hand3 |n $chan]} {
    set access "Channel Administrator"
  } elseif {[matchattr $hand3 n]} {
    set gaccess "Bot Administrator"
  } elseif {[matchattr $hand3 m]} {
    set gaccess "Botnet Co-Administrator"
  } elseif {[matchattr $hand3 o]} {
    set gaccess "Botnet Operator"
  }

  set rhosts [getuser $hand3 HOSTS]
  set comment [getchaninfo $hand3 $chan]

  putlog "!$nick ($host)! access $chan $hand3"

  if {$bcast == "1"} {
    putquick "PRIVMSG $home :$nick!$host requested to see access for $hand3 on $chan ..showing..."   
  }

  putquick "NOTICE $nick :\002Nickname:\002 \00312$hand2"
  putquick "NOTICE $nick :\002Handle:\002 \00312$hand3"
  putquick "NOTICE $nick :\002Access in $chan:\002 \00312$access"
  putquick "NOTICE $nick :\002Comment:\002 \00312$comment"
  putquick "NOTICE $nick :\002Remote Hostnames:\002 \00312$rhosts" 


  if {[matchattr $hand3 D]} {
    putquick "NOTICE $nick :\0033\002$hand2\002\0034 is a disabled user."
    return 0  
  }

  # Now display global permissions if anoy
  if {$gaccess != ""} {
    putquick "NOTICE $nick :\002Global Permissions:\002\00312 $gaccess"
  }

  return 0
}










